package com.tqz.web.flux.demo.annotated;

import com.tqz.web.flux.demo.entity.User;
import com.tqz.web.flux.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.server.RouterFunction;
import reactor.core.publisher.Mono;

/**
 * <p>webflux支持两种方式，一种是基于springmvc的注解，也就是使用 {@link RestController}，
 * 另一种是function函数式编程，也就是使用 {@link RouterFunction}。
 *
 * @author tianqingzhao
 * @since 2023/3/4 20:39
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/annotation/getUser")
    public User getUser() {
        return new User();
    }

    @RequestMapping("/annotation/saveUser")
    public Mono<User> saveUser(User user) {
        return userService.saveOrUpdate(user);
    }

    @RequestMapping("deleteById")
    public Mono<Void> deleteById(Integer id) {
        return userService.deleteById(id);
    }

    @RequestMapping("updateUser")
    public Mono<User> updateUser(User user) {
        return userService.updateUser(user);
    }

    @RequestMapping("getById")
    public Mono<User> getById(Integer id) {
        return userService.getById(id);
    }
}
